﻿namespace ZCUtil.Algorithm
{
    /// <summary>
    /// 用于辅助的队列
    /// </summary>
    public class Queue
    {
        #region ProtectedField 队列算法
        protected int m_Size;
        protected int m_Head;
        protected int m_Tail;
        #endregion

        #region PublicMethod 队列算法
        public Queue(int size)
        {
            m_Size = size;
            m_Head = m_Tail = 0;
        }

        protected bool Empty()
        {
            return m_Head == m_Tail;
        }

        protected bool Full()
        {
            return m_Head == ((m_Tail + 1) % m_Size);
        }

        protected void Front()
        {
            if (Empty())
            {
                return;
            }
            m_Tail = (m_Tail - 1 + m_Size) % m_Size;
        }

        protected void After()
        {
            if (Full())
            {
                m_Head = (m_Head + 1) % m_Size;
            }
            m_Tail = (m_Tail + 1) % m_Size;
        }
        #endregion
    }
}

